#include "helper/object/std/StandardPointer.h"
#include <sstream>

namespace helper {
namespace object {

StandardPointer::StandardPointer(const void * value) 
: value_(const_cast<void*>(value)) 
{
}
StandardPointer::StandardPointer(void * value)
: value_(value)
{
}
StandardPointer::~StandardPointer() 
{
}
void * StandardPointer::set(const void * value) {
    auto ret = value_;
    if(value != value_){
        value_ = const_cast<void*>(value);
    }
    return ret;
}
const void * StandardPointer::get() const {
    return const_cast<const void *>(value_);
}
void * StandardPointer::get() {
    return value_;
}

std::string StandardPointer::toString() const {
    std::ostringstream oss;
    oss << "StandardPointer:" << value_;
    return oss.str();
}

bool StandardPointer::equals(const Object & obj) const {
    if(this != &obj){
        return obj.isPointer() && value_ == static_cast<const Pointer&>(obj).get();
    }
    return true;
}
Object * StandardPointer::copy() const { 
    return new StandardPointer(value_);
} 

} // end of namespace object
} // end of namespace helper
